package com.davies.learn.feature.reactive;

import java.util.concurrent.Flow;
import java.util.function.Consumer;

/**
 * @author davies
 * @date 2023/8/8 14:07
 */
public class WifeSubscriber
        implements Flow.Subscriber<String>{

    private Flow.Subscription subscription;

    private final Consumer<String> consumer;

    public WifeSubscriber(Consumer<String> consumer) {
        this.consumer = consumer;
    }

    @Override
    public void onSubscribe(Flow.Subscription subscription) {
        this.subscription = subscription;
        this.subscription.request(1);

    }

    @Override
    public void onNext(String item) {
        this.consumer.accept(item);
        this.subscription.request(1);

    }

    @Override
    public void onError(Throwable throwable) {
        throwable.printStackTrace();
    }

    @Override
    public void onComplete() {
        System.out.println("汽车可能报废了");

    }
}
